package com.sky.controller.backstage;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.BackstageWeblistService;
import com.sky.vo.BackstageWeblistVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 贾晓晨
 * @version 1.0
 */
@RestController
@RequestMapping("/backstage/weblist")
@Slf4j
@Api(tags = "后台友情链接管理接口")
public class BackstageWebListController {

    @Autowired
    private BackstageWeblistService backstageWeblistService;

    @GetMapping
    @ApiOperation("获取所有友情链接")
    public Result<PageResult> getAllNotice(BackstageWebListQueryDTO BackstageWebListQueryDTO) {
        PageResult noticeList = backstageWeblistService.getAllNotice(BackstageWebListQueryDTO);
        return Result.success(noticeList);
    }

    @GetMapping("/getWebInfoById/{id}")
    @ApiOperation("根据id获取")
    public Result<BackstageWeblistVO> getWebInfoById(@PathVariable Integer id) {
        BackstageWeblistVO backstageWeblistVO = backstageWeblistService.getWebInfo(id);
        return Result.success(backstageWeblistVO);
    }

    @PutMapping("/changeShipStatus")
    @ApiOperation("修改ship的状态")
    public Result changeShipStatus(@RequestBody BackstageShipChangeStatusDTO backstageShipChangeStatusDTO) {
        backstageWeblistService.changeWebStatus(backstageShipChangeStatusDTO);
        return Result.success("修改状态成功");
    }

    @PutMapping("/changeShipDelete")
    @ApiOperation("软删除")
    public Result changeShipDelete(@RequestBody BackstageShipChangeDeleteDTO backstageShipChangeDeleteDTO) {
        backstageWeblistService.changeWebDelete(backstageShipChangeDeleteDTO);
        return Result.success("软删除成功");
    }

    @PutMapping("/shipUpdate")
    @ApiOperation("更改信息")
    public Result shipUpdate(@RequestBody BackstageShipUpdateDTO backstageShipUpdateDTO) {
        backstageWeblistService.shipUpdate(backstageShipUpdateDTO);
        return Result.success("更改信息成功");
    }
    @PostMapping("/addWebInfo")
    @ApiOperation("新增网站")
    public Result saveFriendPost(@RequestBody WebListDTO webListDTO) {
        backstageWeblistService.saveFriendPost(webListDTO);
        return Result.success("保存成功");
    }
    @DeleteMapping("/deleteWebInfo")
    @ApiOperation("删除网站信息")
    public Result deleteFriendPost(@RequestBody List<Integer> ids) {
        backstageWeblistService.deleteWebInfo(ids);
        return Result.success("删除成功");
    }
}
